﻿//=============================================================
// Copyright (C) 2015 福流网络
// 作 者：江怀玉
// 日 期：2015-4-28
// 描 述：页面基类，所有的aspx页面继承自基类
//        页面基类提供常用的方法和常用的用户信息
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00   2015-4-28   江怀玉           
//=============================================================
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;


using System.Web.UI;
using System.Web.UI.HtmlControls;
using FL.DBModule;
using FL.DBModule.Sys;
using FL.Common;


namespace FL.Web.BackEnd
{
    public  class EditPage : BasePage
    {
        private string _edit_self_script;
        /// <summary>
        /// 编辑页自定义脚本
        /// </summary>
        public string Edit_self_script
        {
            get
            {
                return _edit_self_script;
            }
            set
            {
                _edit_self_script = value;
            }
        }



        protected override void OnInit(EventArgs e)
        {
            IList<t_set_entity> __list = this._bll.GetEntitys<t_set_entity>("table_name='" + this.EntityName + "'");
            t_set_entity entity = __list != null ? __list[0] : null;
            if (entity != null)
            {
                Edit_self_script = entity.edit_self_script;
            }
            base.OnInit(e);
            //this.CreateEntitysInstance();
        }


        public string EditEntityID
        {
            get
            {
                return GetStringFromQueryString("EntityID", "");
            }
        }



        #region 对象操作
        /// <summary>
        /// 当前实体类
        /// </summary>
        public BaseEntity CurrEntity
        {
            get;
            set;
        }


        /// <summary>
        /// 创建实体对象实例
        /// </summary>
        public void CreateEntitysInstance()
        {
            try
            {
                this.CreateEntitysInstance(EntityName);
            }
            catch { }
        }

        /// <summary>
        /// 创建实体对象实例
        /// </summary>
        /// <param name="classname"></param>
        public void CreateEntitysInstance(string EntityName)
        {
            try
            {
                BaseEntity _entitys =  Reflection.CreateEntitysInstance( EntityName) as BaseEntity;
                CurrEntity = _entitys;
            }
            catch (System.Exception ex)
            {

            }
        }
        #endregion

        #region 相关网页信息
        /// <summary>
        /// 获得当前FORM,以便可以该控件容器下添加控件.
        /// </summary>
        /// <returns></returns>
        public System.Web.UI.HtmlControls.HtmlForm GetFormOjbect()
        {
            return GetFormOjbect("Form1");
        }

        public System.Web.UI.HtmlControls.HtmlForm GetFormOjbect(string FormName)
        {
            Control ctrl = new Control();
            ctrl = this.Page.FindControl(FormName);
            if (ctrl is HtmlForm)
            {
                return (HtmlForm)ctrl;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取当前的网页名
        /// </summary>
        /// <returns>返文件名</returns>
        public string GetPageFilePath()
        {
            string str = this.Request.Url.AbsolutePath;
            str = this.Request.RawUrl;
            string[] _StrPageName = this.Request.RawUrl.Split('/');
            return _StrPageName[_StrPageName.Length - 1];
        }


        /// <summary>
        /// 获得客户端IP
        /// </summary>
        /// <returns></returns>
        public string GetClietIp()
        {
            return Request.UserHostAddress;
        }

        /// <summary>
        /// 获得当前的网页的地址
        /// </summary>
        /// <param name="AspxFile"></param>
        /// <returns></returns>
        public string GetPageUrl1(string AspxfileName)
        {
            string str = Request.ApplicationPath;
            str += Request.RawUrl;
            return str;
        }



        /// <summary>
        /// 获取当前网页的虚拟地址
        /// </summary>
        /// <returns></returns>
        public string GetPagePath()
        {
            return this.Request.Path;

        }

        /// <summary>
        /// 获取相关信息
        /// </summary>
        /// <param name="Query"> QueryString </param>
        /// <returns></returns>
        public string GetQueryString(string Query)
        {
            try
            {
                string QueryString = Request.QueryString[Query].ToString();
                return QueryString;
            }
            catch (System.Exception e)
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// 获得最后一级目录
        /// </summary>
        /// <returns></returns>
        public string GetCatalog()
        {
            string[] Catalog = GetPagePath().Split('/');
            return Catalog[Catalog.Length - 2];
        }


        /// <summary>
        /// 通过NAME获得对应的控件的值.
        /// </summary>
        /// <param name="Name"></param>
        public string GetContrlValueByName(string Name)
        {
            string strValue = Request.Form[Name].Trim();
            return strValue;
        }


        #endregion
    }
}
